package diva.pap.merchant;

import static diva.lib.lang.Lang.set;

import android.app.Activity;
import diva.android_library.rpc.Response;
import diva.pap.R;
import diva.pap.SellNotificationPresenter;
import diva.pap.SellNotificationRequest;

public class MerchantSellNotificationPresenter extends SellNotificationPresenter {

  public MerchantSellNotificationPresenter(Activity activity) {
    super(activity);
  }

  @Override
  protected SellNotificationRequest<?> createNotificationRequest() {
    return new MerchantSellNotificationRequest(new Response<MerchantSellNotificationRequest>() {
      public void onReuestDone(MerchantSellNotificationRequest request) {
        onNotificationRequestDone(request);
      }

      public void onReuestFailed() {}
    });
  }

  private void onNotificationRequestDone(MerchantSellNotificationRequest request) {
    super.onNotificationRequestDone(request);
    for (MerchantSellNotificationData data : request.getSells()) {
      String title = getString(R.string.notification_sell_content_title);
      if (set(data.getCampaignName())) title += " - " + data.getCampaignName();
      String text = data.getTotalCost() + "/" + data.getCommission();
      if (set(data.getAffiliateName())) text += " - " + data.getAffiliateName();
      showSellNotification(title, text);
    }
  }

}
